package com.itlzb.blog.common.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    private Integer code;
    private String message;
    private T data;
    private int dataSize;

    public Result(Integer code, String message) {
        this(code, message, null, 0);
    }

    public Result(Integer code, String message, T data) {
        this(code, message, data, 0);
    }

    public static Result<Void> success() {
        return new Result<>(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMessage());
    }

    public static Result<Void> success(String message) {
        return new Result<>(ResponseCodeEnum.SUCCESS.getCode(), message);
    }
    public static <T> Result<T>  success(String message, T data) {
        return new Result<>(ResponseCodeEnum.SUCCESS.getCode(), message, data);
    }

    public static <T> Result<T> success(Integer code, String message, T data) {
        return new Result<>(code, message, data);
    }

    public static Result<Void> fail(Integer code, String message) {
        return new Result<>(code, message);
    }
    public static Result<Void> fail(ResponseCodeEnum err) {
        return new Result<>(err.getCode(), err.getMessage());
    }

    public static Result<Void> fail(String err) {
        return new Result<>(220, err);
    }



}
